home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bisonpcb.zip / MAIN.C < prev    next >
C/C++ Source or Header  |  1987-09-18  |  4KB  |  146 lines

  1. /* Top level entry point of bison,
  2.    Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
  3.   
  4. BISON is distributed in the hope that it will be useful, but WITHOUT ANY
  5. WARRANTY.  No author or distributor accepts responsibility to anyone
  6. for the consequences of using it or for whether it serves any
  7. particular purpose or works at all, unless he says so in writing.
  8. Refer to the BISON General Public License for full details.
  9.   
  10. Everyone is granted permission to copy, modify and redistribute BISON,
  11. but only under the conditions described in the BISON General Public
  12. License.  A copy of this license is supposed to have been given to you
  13. along with BISON so you can know your rights and responsibilities.  It
  14. should be in a file named COPYING.  Among other things, the copyright
  15. notice and this notice must be preserved on all copies.
  16.   
  17.  In other words, you are welcome to use, share and improve this program.
  18.  You are forbidden to forbid anyone else to use, share and improve
  19.  what you give them.   Help stamp out software-hoarding!  */
  20.  
  21. /*
  22.  * Port to PC by Whit Gregg
  23.  *               Nourse, Gregg & Browne, Inc.
  24.  *         1 Horizon Road
  25.  *         Fort Lee, NJ  07024
  26.  */
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include "machine.h"
  32. #include "func.h"
  33.  
  34. extern int lineno;
  35. extern int verboseflag;
  36.  
  37.  
  38. void 
  39. main(argc, argv)        /* WG */
  40.     int argc;
  41.     char *argv[];
  42.  
  43. {
  44.     printf("\n Bison  ( )");
  45.     printf("\n         @\n");
  46.     printf("\n    author: Bob Corbett and Richard Stallman");
  47.     printf("\n   PC port: Whitfield Gregg\n");
  48.    printf("\n   Microsoft C Compact model revisions : Bill Davis\n");
  49.     lineno = 0;
  50.     getargs(argc, argv);
  51.     openfiles();
  52.  
  53.     /*
  54.      * read the input.  Copy some parts of it to fguard, faction, ftable
  55.      * and fattrs. In file reader. The other parts are recorded in the
  56.      * grammar; see gram.h.  
  57.      */
  58.     reader();
  59.  
  60.     /*
  61.      * record other info about the grammar.  In files derives and
  62.      * nullable.  
  63.      */
  64.     set_derives();
  65.     set_nullable();
  66.  
  67.     /*
  68.      * convert to nondeterministic finite state machine.  In file LR0.
  69.      * See state.h for more info.  
  70.      */
  71.     generate_states();
  72.  
  73.     /* make it deterministic.  In file lalr.  */
  74.     lalr();
  75.  
  76.     /*
  77.      * Find and record any conflicts: places where one token of lookahead
  78.      * is not enough to disambiguate the parsing.  In file conflicts.
  79.      * Currently this does not do anything to resolve them; the trivial
  80.      * form of conflict resolution that exists is done in output.  
  81.      */
  82.     initialize_conflicts();
  83.  
  84.     /* print information about results, if requested.  In file print. */
  85.     if (verboseflag)
  86.         verbose();
  87.     else
  88.         terse();
  89.  
  90.     /* output the tables and the parser to ftable.  In file output. */
  91.     output();
  92.     done(0);
  93.     }
  94.  
  95.  
  96.  
  97. /* functions to report errors which prevent a parser from being generated */
  98.  
  99. /* JF changed to output error message in standard format.  Just like CC */
  100. void 
  101. fatal(s)            /* WG */
  102.     char *s;
  103. {
  104.     extern char *infile;
  105.  
  106.     fprintf(stderr, "\"%s\", line %d: %s\n", infile, lineno, s);
  107.     done(1);
  108.     }
  109.  
  110.  
  111. /* JF changed to accept/deal with variable args.  Is a real kludge since
  112.    we don't support _doprnt calls */
  113. /*VARARGS1*/
  114. void 
  115. fatals(fmt, x1, x2, x3, x4, x5, x6, x7, x8)    /* WG */
  116.     char *fmt;
  117. {
  118.     char buffer[200];
  119.  
  120.     sprintf(buffer, fmt, x1, x2, x3, x4, x5, x6, x7, x8);
  121.     fatal(buffer);
  122.     }
  123.  
  124.  
  125.  
  126. void 
  127. toomany(s)            /* WG */
  128.     char *s;
  129. {
  130.     char buffer[200];
  131.  
  132.     /* JF new msg */
  133.     sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
  134.     fatal(buffer);
  135.     }
  136.  
  137.  
  138.  
  139. void 
  140. berror(s)            /* WG */
  141.     char *s;
  142. {
  143.     fprintf(stderr, "internal error, %s\n", s);
  144.     abort();
  145.     }
  146.